<template>
    <div class="latiao">
        <div class="la-one" v-for="(item, index) in name " :key="index">
            <div class="la-one-r">
                <div class="la-one-q">{{ item.uname2 }}</div>
                <div class="la-one-qq">{{ item.uname3 }}元/袋</div>
                <!-- item 数组的每一项  intex 数组的下标 -->
            </div>
            <div class="la-one-w">
                <div class="la-one-ww" @click="setName11(index)">-</div>
                <div class="la-one-e">{{ item.uname4 }}</div>
                <div class="la-one-ee" @click="setName1(index)">+</div>
            </div>
        </div>
        <div class="la-one-rr" @click="setName12()">支付</div>
        <div class="la-two" v-if="uname" @click="uname = false">
            <div class="la-two-qq">总价格：{{ uname6 }}</div>
        </div>
    </div>
</template>

<script>
export default {
    name: "",
    /*1. Vue扩展 */
    extends: "", // extends和mixins都扩展逻辑，需要重点放前面
    mixins: [],
    components: {},
    /* 2. Vue数据 */
    props: {},
    model: { prop: "", event: "" }, // model 会使用到 props
    data() {
        return {
            uname: false,
            uname6: 0,
            uname1: 0,
            name: [{ uname2: '辣条', uname3: 10, uname4: 0 }, { uname2: '香蕉', uname3: 20, uname4: 0 }, { uname2: '苹果', uname3: 5, uname4: 0 },]
        };
    },
    computed: {},
    watch: {}, // watch 监控的是 props 和 data，有必要时监控computed
    /* 3. Vue资源 */
    filters: {},
    directives: {},
    /* 4. Vue生命周期 */
    created() { },
    mounted() { },
    destroy() { },
    /* 5. Vue方法 */
    methods: {
        setName() {
            this.uname = true
        },
        // setName1(itemq) {
        //     itemq.uname4 = itemq.uname4 + 1

        // },
        // setName11(itemw) {
        //     if (itemw.uname4 > 0) {
        //         itemw.uname4 = itemw.uname4 - 1
        //     }
        // },
        setName1(itemq) {
            this.name[itemq].uname4 = this.name[itemq].uname4 + 1 

        },
        setName11(itemw) {
            if ( this.name[itemw].uname4 > 0) {
                this.name[itemw].uname4 = this.name[itemw].uname4 - 1 
            }
        },
        setName12() {
            this.uname6 = 0
            for (let i = 0; i < this.name.length; i++) {
                this.uname6 = this.uname6 + this.name[i].uname3 * this.name[i].uname4
            }
            this.uname = true
        },
    }
};
</script>


<style scoped lang="scss">
.latiao {
    width: 100%;
    height: 100vh;
    border: 1px solid red;

    .la-one {
        height: 150px;
        margin: 15px 10px 0 10px;
        border: 1px solid red;
        display: flex;
        background-color: antiquewhite;

        .la-one-r {
            margin: 15px 10px 0 10px;

            .la-one-q {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                color: brown;
            }

            .la-one-qq {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                margin-top: 15px;
                color: brown;
            }

            .la-one-qqq {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                margin-top: 15px;
                color: brown;
            }
        }

        .la-one-w {
            margin-left: auto;
            display: flex;
            align-items: center;

            .la-one-ww {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                color: red;
                border-radius: 5px;
            }

            .la-one-e {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                margin-left: 10px;
                color: red;
                border-radius: 5px;
            }

            .la-one-ee {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                margin-left: 10px;
                color: red;
                border-radius: 5px;
            }
        }
    }

    .la-one-rr {
        height: 40px;
        border: 1px solid red;
        border-radius: 10px;
        background-color: blue;
        font-size: 17px;
        font-weight: 600;
        color: aliceblue;
        text-align: center;
        line-height: 40px;
        position: fixed;
        bottom: 0;
        right: 15px;
        left: 15px;


    }

    .la-two {
        bottom: 0;
        top: 0;
        left: 0;
        right: 0;
        position: fixed;
        background-color: rgba(0, 0, 0, 0.2);
        justify-content: center;
        align-items: center;
        display: flex;

        .la-two-qq {
            line-height: 60px;
            height: 60px;
            width: 300px;
            text-align: center;
            font-size: 24px;
            font-weight: 600;
            color: red;
            background-color: white;
            border-radius: 10px;
        }
    }
}
</style>